﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Hi_Baidu.Packet.InPacket
{
    class BoardCast_AddFriendReplyPacket : BaseInPackage
    {
        public BoardCast_AddFriendReplyPacket(InPackage inpackage) : base(inpackage)
        {
        }

        public override void InitPackage()
        {
            int Offset = 0;
            //用户名长度
            byte[] UsernameLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, UsernameLength, 0, 4);
            Offset += 4;
            //用户名长度
            byte[] Username = new byte[BitConverter.ToInt32(UsernameLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Username, 0, Username.Length);
            Offset += Username.Length;
            //好友长度
            byte[] FriendLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, FriendLength, 0, 4);
            Offset += 4;
            //好友
            byte[] Friend = new byte[BitConverter.ToInt32(FriendLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Friend, 0, Friend.Length);
            Offset += Friend.Length;
            //分组ID
            byte[] ItemId = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, ItemId, 0, 4);
            Offset += 4;
            //好友ID长度
            byte[] FriendId = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, FriendId, 0, 4);
            Offset += 4;            
            //是否添加成功的标志位
            byte[] AddState = new byte[1];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, AddState, 0, 1);
            Offset += 1;

            this.DIC_CONTENT.Add("USERNAME", Username);
            this.DIC_CONTENT.Add("FRIENDUSERNAME", Friend);
            this.DIC_CONTENT.Add("ITEMID", ItemId);
            this.DIC_CONTENT.Add("FRIENDID", FriendId);
            this.DIC_CONTENT.Add("ADDSTATE", AddState);
        }

        /// <summary>
        ///     获得好友用户名
        /// </summary>
        /// <returns></returns>
        public String GetFriendName()
        {
            return Encoding.Default.GetString(this.DIC_CONTENT["FRIENDUSERNAME"]);
        }

        /// <summary>
        ///     获得分组ID
        /// </summary>
        /// <returns></returns>
        public String GetItemId()
        {
            return BitConverter.ToInt32(this.DIC_CONTENT["ITEMID"], 0).ToString();
        }

        /// <summary>
        ///     获得好友ID
        /// </summary>
        /// <returns></returns>
        public String GetFriendId()
        {
            return BitConverter.ToInt32(this.DIC_CONTENT["FRIENDID"], 0).ToString();
        }

        /// <summary>
        ///     获得添加状态
        /// </summary>
        /// <returns></returns>
        public bool GetAddState()
        {
            return BitConverter.ToBoolean(this.DIC_CONTENT["ADDSTATE"], 0);
        }
    }
}
